#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import os
import unittest
import tempfile

from jute.db import SSTableWriter,SSTableReader

class   SSTable01TestCase(unittest.TestCase) :
    def setUp(self) :
        pass
        ## setUp()

    def tearDown(self) :
        pass
        ## tearDown()

    def testSimple(self) :
        tmpdir = tempfile.gettempdir()
        tmpfilename = os.sep.join((tmpdir, 'sstable.wtest'))
        
        writer = SSTableWriter(tmpfilename, key_count=1000)
        for i in range(500) :
            writer.append('hello-%05d' % i,'world-%05d' % i)

        writer.close()

        reader = SSTableReader(tmpfilename)
        for i in (127, 128, 129) :
            key = 'hello-%05d' % i
            value_wanted = 'world-%05d' % i
            value = reader.get(key)
            self.assertEqual(value, value_wanted)
        for i in range(100) :
            k = 5 * i
            key = 'hello-%05d' % k
            value_wanted = 'world-%05d' % k
            value = reader.get(key)
            self.assertEqual(value, value_wanted)
        for i in range(500) :
            key = 'hello-%05d' % i
            value_wanted = 'world-%05d' % i
            value = reader.get(key)
            self.assertEqual(value, value_wanted)
        reader.close()
        ## testSimple()

    ## class SSTable01TestCase


if __name__ == '__main__' :
    unittest.main()

